﻿@{
    ViewBag.Title = "Index";
    ViewBag.Title = "材料整理首页";
    string type = ViewBag.Type;
}
<style type="text/css">
    div .div_rmenu {
        background-color: #555555;
        text-align: left;
        padding: 2px;
    }

        div .div_rmenu li {
            list-style: none;
        }

        div .div_rmenu ul {
            margin: 1px 0;
            padding: 0 5px;
            cursor: pointer;
            list-style: none outside none;
            background-color: #DFDFDF;
        }

            div .div_rmenu ul:hover {
                background-color: #b8d0d6;
            }

            div .div_rmenu ul li {
                margin: 0;
                padding: 2px 0;
            }

    .ztree .span1 {
        color: #0a9c1d;
    }

    .ztree .span2 {
        color: #ff6a00;
    }

    .ztree .span3 {
        color: #0026ff;
    }
</style>
<script type="text/javascript">
    var jgzl_cllx_zTree_@(type);
    var jgzl_cllx_zTree_setting = {
        treeObjId: "jgzl_cllx_zTree_@(type)",
        isSimpleData: true,              //数据是否采用简单 Array 格式，默认false
        treeNodeKey: "id",               //在isSimpleData格式下，当前节点id属性
        treeNodeParentKey: "pId",        //在isSimpleData格式下，当前节点的父节点id属性
        showLine: true,                  //是否显示节点间的连线
        checkable: false,                  //每个节点上是否显示 CheckBox
        async: true,
        asyncUrl: "/CompletionMaterials/ProFileType/ProFileTypeJson",  //获取节点数据的URL地址
        asyncParam: ["id"],
        asyncParamOther: { "type": "@(type)" },
        callback: {
            click: jgzl_cllx_zTree_click,
            rightClick: zTreeOnRightClick@(type)
        }
    };
    //点击事件
    function jgzl_cllx_zTree_click(event, treeId, treeNode) {
        var tab_i = 0;
        if ($("#ul_profiletype@(type)").length > 0) {
            var i = 0;
            $("#ul_profiletype@(type) li").each(function () {
                if ($(this).attr("class") == "selected") {
                    tab_i = i;
                }
                i++;
            });
        }
        $("#jgzl_cllx_list_@(type)").loadUrl('/CompletionMaterials/ProFileType/Detail', "tab_i=" + tab_i + "&type=@(type)&id=" + treeNode.id, function (message) {
            $('#jgzl_cllx_list_@(type)').parent().find("[layoutH]").layoutH();
        });
    }
    //右击事件
    var rMenu@(type);
    function zTreeOnRightClick@(type)(event, treeId, treeNode) {
        var lin = 0;
        $("#rMenu@(type) ul").each(function () {
            var lih = $(this).find("li").html();
            if (lih == null) {
                $(this).html("");
            } else if (lih.replace(/\s*/g, "") == "") {
                $(this).html("");
            } else {
                lin++;
            }
        });
        if (lin > 0) {
            if (treeNode && !treeNode.noR) {
                if (treeNode.fdId == "BFADFD31-5048-423E-B8B8-D479D15F7879")
                    $("#li_bridge_@(type)").attr("style", "display:block;");
                else
                    $("#li_bridge_@(type)").attr("style", "display:none;");
                jgzl_cllx_zTree_@(type).selectNode(treeNode);
                showRMenu@(type)("node", event.clientX - 190, event.clientY - 140);
            } else {
                hideRMenu@(type)();
            }
        }
    }
    function showRMenu@(type)(type, x, y) {
        $("#rMenu@(type) ul").show();
        $("#rMenu@(type)").css({ "top": y + "px", "left": x + "px", "visibility": "visible" });
    }
    function hideRMenu@(type)() {
        if (rMenu@(type))
            rMenu@(type).style.visibility = "hidden";
    }
    //选择子类型
    function selTreeNode@(type)() {
        hideRMenu@(type)();
        var node = jgzl_cllx_zTree_@(type).getSelectedNode();
        if (node != null) {
            var options = {
                mask: true,
                width: 480, height: 480,
                maxable: eval("true"),
                resizable: eval("true")
            };
            $.pdialog.open("/CompletionMaterials/ProFileType/Select?bridge=false&id=" + node.id, "jgzl_xz_cllx", "选择材料类型", options);
        }
    }
    //添加自定义类型
    function addTreeNode@(type)() {
        hideRMenu@(type)();
        var node = jgzl_cllx_zTree_@(type).getSelectedNode();
        if (node != null) {
            var options = {
                mask: true,
                width: 600, height: 520,
                maxable: eval("true"),
                resizable: eval("true")
            };
            $.pdialog.open("/CompletionMaterials/ProFileType/CustomCreat?id=" + node.id, "jgzl_tj_zdylx", "添加自定义类型信息", options);
        }
    }
    //添加桥梁信息
    function addBridge@(type)() {
        hideRMenu@(type)();
        var node = jgzl_cllx_zTree_@(type).getSelectedNode();
        if (node != null) {
            var options = {
                mask: true,
                width: 400, height: 400,
                maxable: eval("true"),
                resizable: eval("true")
            };
            $.pdialog.open("/CompletionMaterials/ProFileType/Select?bridge=true&id=" + node.id, "jgzl_tj_qlxx", "添加桥梁信息", options);
        }
    }
    //修改类型
    function editTreeNode@(type)() {
        hideRMenu@(type)();
        var node = jgzl_cllx_zTree_@(type).getSelectedNode();
        if (node != null) {
            var options = {
                mask: true,
                width: 600, height: 520,
                maxable: eval("true"),
                resizable: eval("true")
            };
            $.pdialog.open("/CompletionMaterials/ProFileType/Edit?id=" + node.id, "jgzl_xg_lxxx", "修改类型信息", options);
        }
    }
    //删除类型
    function delTreeNode@(type)() {
        hideRMenu@(type)();
        var node = jgzl_cllx_zTree_@(type).getSelectedNode();
        if (node != null) {
            alertMsg.confirm("将同时删除与其关联的案卷信息，您确定要删除吗？", {
                okCall: function () {
                    $.post("/CompletionMaterials/ProFileType/Delete", { id: node.id }, refre_jgzl_cllx_index, "json");
                }
            });
        } else {
            alertMsg.error("请选一条信息！");
        }
    }
    //刷新ztree
    function refre_jgzl_cllx_index(json) {
        DWZ.ajaxDone(json);
        if (json.statusCode == DWZ.statusCode.ok) {
            //添加刷新树
            if (json.type == "add") {
                var pNode = null;
                if (json.pId != null) {
                    pNode = jgzl_cllx_zTree_@(type).getNodeByParam("id", json.pId);
                    var pName = pNode.name;
                    if (pName.indexOf("</span>") > 0) {
                        pNode.name = pName.substr(pName.indexOf(")") + 1);
                        jgzl_cllx_zTree_@(type).updateNode(pNode);
                    }
                }
                jgzl_cllx_zTree_@(type).addNodes(pNode, { pId: json.pId, id: json.id, name: json.name }); //页面上添加节点 
                var node = jgzl_cllx_zTree_@(type).getNodeByParam("id", json.id);
                $("#" + node.tId).initUI();
                jgzl_cllx_zTree_@(type).selectNode(node);
                var tab_i = 0;
                if ($("#ul_profiletype@(type)").length > 0) {
                    var i = 0;
                    $("#ul_profiletype@(type) li").each(function () {
                        if ($(this).attr("class") == "selected") {
                            tab_i = i;
                        }
                        i++;
                    });
                }
                $("#jgzl_cllx_list_@(type)").loadUrl('/CompletionMaterials/ProFileType/Detail', "tab_i=" + tab_i + "&type=@(type)&id=" + json.id, null);
                $.pdialog.closeCurrent();
            }
            //修改刷新树
            if (json.type == "edit") {
                var node = jgzl_cllx_zTree_@(type).getNodeByParam("id", json.id);
                node.name = json.name;
                jgzl_cllx_zTree_@(type).updateNode(node);
                jgzl_cllx_zTree_@(type).selectNode(node);
                var tab_i = 0;
                if ($("#ul_profiletype@(type)").length > 0) {
                    var i = 0;
                    $("#ul_profiletype@(type) li").each(function () {
                        if ($(this).attr("class") == "selected") {
                            tab_i = i;
                        }
                        i++;
                    });
                }
                $("#jgzl_cllx_list_@(type)").loadUrl('/CompletionMaterials/ProFileType/Detail', "tab_i=" + tab_i + "&type=@(type)&id=" + json.id, null);
                $.pdialog.closeCurrent();
            }
            //删除刷新树
            if (json.type == "delete") {
                var node = jgzl_cllx_zTree_@(type).getNodeByParam("id", json.id);
                jgzl_cllx_zTree_@(type).removeNode(node);
                $("#jgzl_cllx_list_@(type)").html("");
            }
            //选择子节点刷新树
            if (json.type == "sel") {
                var node = jgzl_cllx_zTree_@(type).getNodeByParam("id", json.id);
                node.isParent = json.isParent;
                if (json.isParent) {
                    if (node.name.indexOf("</span>") > 0) {
                        node.name = node.name.substr(node.name.indexOf(")") + 1);
                    }
                }
                jgzl_cllx_zTree_@(type).updateNode(node);
                jgzl_cllx_zTree_@(type).reAsyncChildNodes(node, "refresh", true)
                jgzl_cllx_zTree_@(type).expandNode(node, true, true, true);
            }
            //审核刷新树
            if (json.type == "check") {
                var node = jgzl_cllx_zTree_@(type).getNodeByParam("id", json.id);
                node.name = json.name;
                jgzl_cllx_zTree_@(type).updateNode(node);
            }
        }
    }
    //初始化
    $(document).ready(function () {
        hideRMenu@(type)();
        $.getJSON(
         "/CompletionMaterials/ProFileType/ProFileTypeJson?type=@(type)",
           function (data) {
               jgzl_cllx_zTree_@(type) = $("#jgzl_cllx_zTree_@(type)").zTree(jgzl_cllx_zTree_setting, data);
               if (data.length > 0) {
                   $("#jgzl_cllx_list_@(type)").loadUrl('/CompletionMaterials/ProFileType/Detail', "tab_i=0&type=@(type)&id=" + data[0].id, function (message) {
                       $('#jgzl_cllx_list_@(type)').parent().find("[layoutH]").layoutH();
                   });
               }
           });
        rMenu@(type) = document.getElementById("rMenu@(type)");
        $("#jgzl_cllx_zTree_@(type)").bind("mousedown",
               function (event) {
                   if (!(event.target.id == "rMenu@(type)" || $(event.target).parents("#rMenu@(type)").length > 0)) {
                       rMenu@(type).style.visibility = "hidden";
                   }
               });
    });
</script>


<div class="page" style="border-top: 1px solid #b8d0d6;" layouth="1">
    <div class="leftPanel" style="width: 300px;">
        <div class="panelBar" style="width: 298px;">
            <ul class="toolBar" style="width: 100px; float: left;">
                <li>@Html.PermissionButton("CompletionMaterials.ProFileType.Create" + type, "CompletionMaterials_ProFileType_Create" + type, "add", "/CompletionMaterials/ProFileType/Create?type=" + type, "new", "dialog", "添加根类型", "true", "600", "520", "添加根类型")</li>

            </ul>
            <ul style="width: 160px;">
                <li class="ztree">(<span class="span1">已归档</span>/<span class="span2">已审核</span>/<span class="span3">文件数</span>)</li>
            </ul>
        </div>
        <div class="pageContent" layouth="28">
            <ul id="jgzl_cllx_zTree_@(type)" class="ztree"></ul>
            <div id="rMenu@(type)" class="div_rmenu" style="position: absolute; visibility: hidden;">
                <li>
                    <ul onclick="selTreeNode@(type)();">
                        <li>
                            @Html.PermissionButton("CompletionMaterials.ProFileType.Sel" + type, "CompletionMaterials_ProFileType_Sel" + type, "javascript:void(0);", "选择子类型", new Dictionary<string, object> { { "style", "color:black;" } })
                        </li>
                    </ul>
                    <ul onclick="addBridge@(type)();">
                        <li id="li_bridge_@(type)" style="display:none;">
                            @Html.PermissionButton("CompletionMaterials.ProFileType.Bri" + type, "CompletionMaterials_ProFileType_Bri" + type, "javascript:void(0);", "添加桥梁信息", new Dictionary<string, object> { { "style", "color:black;" } })
                        </li>
                    </ul>
                    <ul onclick="addTreeNode@(type)();">
                        <li>
                            @Html.PermissionButton("CompletionMaterials.ProFileType.Add" + type, "CompletionMaterials_ProFileType_Add" + type, "javascript:void(0);", "添加自定义类型", new Dictionary<string, object> { { "style", "color:black;" } })
                        </li>
                    </ul>
                    <ul onclick="editTreeNode@(type)();">
                        <li>
                            @Html.PermissionButton("CompletionMaterials.ProFileType.Edit" + type, "CompletionMaterials_ProFileType_Edit" + type, "javascript:void(0);", "修改类型", new Dictionary<string, object> { { "style", "color:black;" } })
                        </li>
                    </ul>
                    <ul onclick="delTreeNode@(type)();">
                        <li>
                            @Html.PermissionButton("CompletionMaterials.ProFileType.Del" + type, "CompletionMaterials_ProFileType_Del" + type, "javascript:void(0);", "删除类型", new Dictionary<string, object> { { "style", "color:black;" } })
                        </li>
                    </ul>
                </li>
            </div>
        </div>
    </div>
    <div id="jgzl_cllx_list_@(type)"  class="rightPanel" >
    </div>
</div>

